home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- #
- # /usr/ns-home/sgi_config/admin/configure
- #
- # This script fixes up the netscape admin server 2.X configuration files
- # if the system name, primary IP address, or domain name is changed.
- #
- # It is typically called as an exitop upon installation of the image and from
- # /etc/init.d/ns_admin each time the system boots.
- #
- # The script first checks to see if any key system configuration has changed.
- # If so, it does its work
- #
- # $Revision: 1.1 $
- #
- #
-
- SED=/usr/bin/sed
- GREP=/usr/bin/grep
- SORT=/usr/bin/sort
- HEAD=/usr/bsd/head
- CPP='/bin/cp -p'
- MV=/bin/mv
- RM=/bin/rm
- CAT=/usr/bin/cat
-
- IS_ON=/sbin/chkconfig
-
- if $IS_ON verbose; then
- ECHO=echo
- else
- ECHO=:
- fi
-
- NS_HOME=/usr/ns-home
- CONFIG_DIR=$NS_HOME/sgi_config/admin
-
- HOST_FLAG=%%HOSTNAME%%
- DOMAIN_FLAG=%%DOMAINNAME%%
- ADDR_FLAG=%%NETADDR%%
-
- if [ -f ${CONFIG_DIR}/%%DOMAINNAME%% -a -f ${CONFIG_DIR}/%%HOSTNAME%% -a -f ${CONFIG_DIR}/%%NETADDR%% ]; then
- :
- else
- $ECHO "$0: config files missing from ${CONFIG_DIR}"
- exit 1
- fi
-
- OLDDOMAIN=`$CAT ${CONFIG_DIR}/%%DOMAINNAME%%`
- OLDHOST=`$CAT ${CONFIG_DIR}/%%HOSTNAME%%`
- OLDADDR=`$CAT ${CONFIG_DIR}/%%NETADDR%%`
-
- NAMELIST=`$CAT ${CONFIG_DIR}/namelist`
- EDITLIST=`$CAT ${CONFIG_DIR}/editlist | \
- $SED "s/$HOST_FLAG/$OLDHOST/" | $SED "s/$DOMAIN_FLAG/$OLDDOMAIN/" | \
- $SED "s/$ADDR_FLAG/$OLDADDR/"`
-
- ADM_NAME_LIST=${NS_HOME}/admserv/${NAMELIST}
-
-
- # first get the current hostname and domainname and address
- # hostname
- #
- canonname=`/usr/etc/configmail get mycanonname`
-
- hostname=`/usr/bin/echo $canonname | $SED 's/\..*//'`
- if [ "$hostname" = "" ]; then
- $ECHO "$0: Cannot get hostname for system."
- exit 1
- fi
-
- #domainname
- #
- domainname=`/usr/etc/configmail get localdomain`
- if [ "$domainname" = "" ]; then
- domainname=$DOMAIN_FLAG
- fi
-
- #netaddr
- #
- netaddr=`$GREP $canonname /etc/hosts | $GREP -v "^#" | $SED 's/[ ].*//' | $SORT -u | $HEAD -1`
- if [ "$netaddr" = "" ]; then
- netaddr=`$GREP $hostname /etc/hosts | $GREP -v "^#" | $SED 's/[ ].*//' | $SORT -u | $HEAD -1`
- fi
- if [ "$netaddr" = "" ]; then
- netaddr=$ADDR_FLAG
- fi
-
- # See if anything has changed -- Don't do this. For the ns_admin configuration
- # files we'll always attempt to edit them. Since they are config(suggest), the
- # user could move the .N file over the existing one at any time. This way we
- # always catch it. Since there is such a small file set, this is not an
- # expensive solution.
- #
- #if [ "$domainname" = "$OLDDOMAIN" -a "$hostname" = "$OLDHOST" -a "$netaddr" = "$OLDADDR" ]; then
- # $ECHO "$0: no changes"
- # exit 0
- #fi
-
- # Now edit the files -- THIS MUST BE DONE BEFORE CHANGING DIRECTORY NAMES
- # Note I always try to change the canon names (the *_FLAG) because there may be a .N
- # file that the user moves over the existing one. The special expressions
- # "^ServerName" and "^Hosts" are need to be called out in particular
- # because host names can look like other strings. Note that these SED commands
- # must be run in this order.
- #
- for dir in $ADM_NAME_LIST
- do
- for file in $EDITLIST
- do
- $CPP $NS_HOME/$file $NS_HOME/$file.tmp #preserver owner, permission, etc
- $SED "s/^\(ServerName[ ]*\).*/\1$canonname/" $NS_HOME/$file | \
- $SED "/^Hosts[ ]*/s/($HOST_FLAG|/($canonname|/" | \
- $SED "/^Hosts[ ]*/s/|$HOST_FLAG)/|$canonname)/" | \
- $SED "/^Hosts[ ]*/s/|$HOST_FLAG|/|$canonname|/" | \
- $SED "/^Hosts[ ]*/s/($HOST_FLAG)/($canonname)/" | \
- $SED "/^Hosts[ ]*/s/($OLDHOST|/($canonname|/" | \
- $SED "/^Hosts[ ]*/s/|$OLDHOST)/|$canonname)/" | \
- $SED "/^Hosts[ ]*/s/|$OLDHOST|/|$canonname|/" | \
- $SED "/^Hosts[ ]*/s/($OLDHOST)/($canonname)/" | \
- $SED "s/^\(Hosts[ ]*\)$HOST_FLAG/\1$canonname/" | \
- $SED "s/^\(Hosts[ ]*\)$OLDHOST[ ]*$/\1$canonname/" | \
- $SED "s/$HOST_FLAG.$DOMAIN_FLAG/$canonname/g" | \
- $SED "s/$HOST_FLAG.$OLDDOMAIN/$canonname/g" | \
- $SED "s/$OLDHOST.$OLDDOMAIN/$canonname/g" | \
- $SED "s/$DOMAIN_FLAG/$domainname/g" | \
- $SED "s/$OLDDOMAIN/$domainname/g" | \
- $SED "s/$ADDR_FLAG/$netaddr/g" | \
- $SED "s/$OLDADDR/$netaddr/g" >$NS_HOME/$file.tmp
- $MV $NS_HOME/$file.tmp $NS_HOME/$file
- done
- done
-
- # Remember the current host information
- #
- /usr/bin/echo $hostname >${CONFIG_DIR}/%%HOSTNAME%%
- /usr/bin/echo $domainname >${CONFIG_DIR}/%%DOMAINNAME%%
- /usr/bin/echo $netaddr >${CONFIG_DIR}/%%NETADDR%%
-
- exit 0
-
-